/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: Pegasus  Date: 2019-02-13 Time: 23:07
 */

import {Action} from "../../../configuration/ActionCreator"
import {FetchStatus, RequestAction, RequestMethod} from "../../../configuration/RequestConfiguration";
import {AppRequestPath} from "../../../configuration/AppConfig";
import {API_PROCEDURE2} from "../../../constant/API";
import global from "../../../configuration/global";

//------------------------------获取默认值----------------------------------
export const DailyOrderSweepDefault = 'DailyOrderSweepDefault';
export const dailyOrderSweepDefault = (str) => {
    let action = Action(DailyOrderSweepDefault);
    return dispatch => dispatch(request_WHSKDailyOrderSweepDefault(action, str))
};

export const request_WHSKDailyOrderSweepDefault = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKDailyOrderSweepDefault',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onDailyOrderSweepDefault = (state = {}, action) => {
    switch (action.type) {
        case DailyOrderSweepDefault: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


//------------------------------获取房态盘默认值----------------------------------
export const RetrieveRoomsViewAs = 'RetrieveRoomsViewAs';
export const retrieveRoomsViewAs = (str) => {
    let action = Action(RetrieveRoomsViewAs);
    return dispatch => dispatch(request_retrieveRoomsViewAs(action, str))
};

export const request_retrieveRoomsViewAs = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKRetrieveRoomsViewAs',
            'jn': str,
            'jnJson2': JSON.stringify({"output":{"json":"null"}}),
            "jnJson3" : "list",
        },
        action
    )
};

export const onRetrieveRoomsViewAs = (state = {}, action) => {
    switch (action.type) {
        case RetrieveRoomsViewAs: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

// ----------------------------新建订单-------------------------------
export const DailyOrderSweepSave = 'DailyOrderSweepSave';
export const dailyOrderSweepSave = (str) => {
    let action = Action(DailyOrderSweepSave);
    return dispatch => dispatch(requestDailyOrderSweepSave(action, str))
}

export const requestDailyOrderSweepSave = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKDailyOrderSweepSave',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onDailyOrderSweepSave = (state = {}, action) => {
    switch (action.type) {
        case DailyOrderSweepSave: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};



